/*
 * @Description: 
 * @Author: zzj
 * @Date: 2021-09-05 10:26:57
 * @LastEditors: zzj
 * @LastEditTime: 2021-09-05 10:45:30
 */

// 如何改变函数的执行环境

name = "xiaoming";
function sayName(a,b){
    console.log(this,name);
    console.log(a+b);
}
var obj1 = {
    name:"zhangsan",
}
var obj2 = {
    name:"wangwu"
}
sayName(1,2);
sayName.call(obj1,1,2);  //将sayName方法的this指向改变为obj1
sayName.call(obj2);
sayName.apply(obj1,[1,2]);
sayName.bind(obj1)(1,2);  //返回的是一个方法